import { Controller, Get, Redirect ,Query, HttpCode, Header} from '@nestjs/common'
import {User} from './custom-decorator/user';
@Controller('redirect-decorate')
export class RedirectDecorateController {
    @Get('redirect')
    @Redirect('/router-params/res',301)
    redirect() {
        return 'redirect'
    }

    // 重定向方式2
    @Get('redirect2')
    redirect2(@Query('version') version) {
        return {url:'/router-params/res?='+version,statusCode:302}
    }

    // HttpCode更改状态码装饰器
    @Get('httpcode')
    @HttpCode(222)
    httpcode(){
        return 'status code:222'
    }


    // @Header装饰器，设置Header
    @Get('header')
    @HttpCode(222)
    @Header('header-key','header-value')
    @Header('header-key2','header-value2')
    header(){
        return 'status code:222'
    }


    // 自定义参数装饰器
    @Get('custom-user')
    customUser(@User() user,@User('name') name){
        console.log(name)
        return user;
    }
}